package com.atguigu.lease.common.advice;


import com.atguigu.lease.common.result.Result;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 用于返回错误信息
 */
@RestControllerAdvice
public class CustomExceptionHandler {

    @ExceptionHandler(CostomReturnException.class)
    public Result<String> resultException(CostomReturnException e){
        //打印错误信息
        e.printStackTrace();
        //给客户端返回错误信息和错误码
        return Result.fail(e.getCode(),e.getMessage());
    }

    //兜底方法，防止漏掉异常
    @ExceptionHandler(Exception.class)
    public Result<String> ExceptionAll(Exception e){
        e.printStackTrace();
        return Result.fail();

    }
}
